<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
		<title>青年旅行家</title>
		<link rel="stylesheet" type="text/css" href="../css/api.css" />
		<link rel="stylesheet" type="text/css" href="../css/base.css" />
	</head>

	<body>
		<div class="head" id="header">
			<a class="back" href="#" tapmode="" onclick="closeWin()"></a>
			<div class="head-text">
				注册：完善资料
			</div>
		</div>
		<div class="reg-wrap">
			<ul class="reg-form3">
				<li>					
					<a class="upload-pic" href="#" onclick="openEditHead()"><img src="../images/default_img.png" alt="" class='photo round' id='photo'/><span>点击上传头像</span></a>
					<p id="userSN">
						<!--我的旅行家编号：15424445-->
					</p>
				</li>
				<li>
					<p>
						昵称：
					</p>
					<input type="text" name="" placeholder="给自己取个昵称吧！" id='nickName'/>
				</li>
				<li>
					<p>
						所在地：
					</p>
					<input type="text" name="" placeholder="" id='location'/>
				</li>
				<li>
					<p>
						签名：
					</p>
					<textarea id='signature'></textarea>
				</li>
			</ul>
			<div class="reg-next2">
				<a href="#" tapmode="" onclick="done()">注册完成</a>
			</div>
		</div>
	</body>
	<script type="text/javascript" src="../script/api.js"></script>
	<script type="text/javascript" src="../script/app.js"></script>
	<script type="text/javascript" src="../script/util.js"></script>
	<script type="text/javascript" src="../script/dot.min.js"></script>
	<script type="text/javascript" src="../script/zepto.min.js"></script>
	<script type="text/javascript">
				
			function done(){						
			var uid=$api.getStorage('uid');
			//var userData=$api.getStorage('userData');
			var url='/rest/user/updateUser?userId='+uid;
			var photo=$api.getStorage('photo');
			var nickName=$('#nickName').val();			
			var location=$('#location').val();
			var signature=$('#signature').val();
			var data=$api.getStorage('userData');
			data.nickName=nickName;
			data.location=location;
			data.photoBasecode=photo;
			data.signature=signature;
			//data.adress=adress;
			ajaxRequest(url, 'post', data, function(ret, err) {
				if (ret.body) {		
					data.photoBasecode="";
					$api.setStorage('userData',data);
					api.closeWin({name:'win_register_02'});                    
                    log(data);                                                        
					api.closeToWin({
						name: 'root'
					});
					api.execScript({
		                name: 'root',
		                script: "randomSwitchBtn(null,'bbtn01',0);randomSwitchBtn1(null, 'bbtn01',2)"
		            });					
					} else if (ret.error) {
						alert('完善用户资料失败，请直接更新！');
					} else {
						alert('完善用户资料失败，请直接更新！');
					}
					//else
					//	alert(JSON.stringify(err));
				})
		}
		function setPhoto()
		{
			var photo=$api.getStorage('photo');
			var uid=$api.getStorage('uid')|'83';
			if(photo&&uid)
			{
			    var obj=window.document.getElementById('photo');
				obj.src=photo;
			}
		}
		apiready = function() {	
		var $header=$api.byId('header');
		$api.fixIos7Bar($header);		
			//setPhoto();			
			api.addEventListener({
                name: 'setPhoto'
            }, function (ret, err) {
                //msg("OK");
            	setPhoto();
            });
		}
	</script>

</html>